package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class SIGN extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject = null;
    for (int i = 0; i < paramArrayOfObject.length; ++i)
    {
      localObject = paramArrayOfObject[i];
      if (localObject instanceof Number)
      {
        double d = ((Number)localObject).doubleValue();
        if (d > 0.0D)
          return new Integer(1);
        if (d < 0.0D)
          return new Integer(-1);
        if (d == 0.0D)
          return new Integer(0);
      }
    }
    return new Integer(0);
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "SIGN(number):返回数字的符号。当数字为正数时返回 1，为零时返回 0，为负数时返回 -1。\nNumber:为任意实数。\n示例:\nSIGN(10) 等于 1\nSIGN(4-4) 等于 0\nSIGN(-0.00001) 等于 -1\n";
  }

  public String getEN()
  {
    return "SIGN(number): Determines the sign of a number. Returns 1 if the number is positive, zero (0) if the number is 0, and -1 if the number is negative.\nNumber is any real number.\n\nExample:\n   SIGN(10) = 1\n   SIGN(4-4) = 0\n   SIGN(-0.00001) = -1\n";
  }
}